<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns1="ddi:instance:3_1" xmlns:a="ddi:archive:3_1" xmlns:r="ddi:reusable:3_1" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="ddi:dcelements:3_1" xmlns:ns7="http://purl.org/dc/elements/1.1/" xmlns:cm="ddi:comparative:3_1" xmlns:d="ddi:datacollection:3_1" xmlns:l="ddi:logicalproduct:3_1" xmlns:c="ddi:conceptualcomponent:3_1" xmlns:ds="ddi:dataset:3_1" xmlns:p="ddi:physicaldataproduct:3_1" xmlns:pr="ddi:ddiprofile:3_1" xmlns:s="ddi:studyunit:3_1" xmlns:g="ddi:group:3_1" xmlns:pi="ddi:physicalinstance:3_1" xmlns:m3="ddi:physicaldataproduct_ncube_inline:3_1" xmlns:m1="ddi:physicaldataproduct_ncube_normal:3_1" xmlns:m2="ddi:physicaldataproduct_ncube_tabular:3_1" xmlns:xf="http://www.w3.org/2002/xforms">

	<xsl:template match="/">
		<xsl:result-document href="./ddi-codebook/menu.html">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>DDI Codebook - </title>
				<style type="text/css"> 
					* {margin:0.1em; padding:0.1em;}
					ul {margin-left:1em};
				</style>
			</head>
			<body>
				<h1 style="color:green;">DDI</h1>
				<h2><span style="color:blue">Code</span><span style="color:magenta;margin-left:-0.3em;">r</span> 2.0</h2>
				<div style="">
				<xsl:apply-templates select="//CodeScheme">
					<xsl:with-param name="level">0</xsl:with-param>
				</xsl:apply-templates>
				</div>
			</body>
		</html>
		</xsl:result-document>
	</xsl:template>
	<xsl:template match="CodeScheme">
		<xsl:apply-templates select="Label" />
		<xsl:apply-templates select="Code"/>	
	</xsl:template>
	<xsl:template match="Label">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="Code">
		<xsl:variable name="categoryID">
			<xsl:value-of select="CategoryReference/ID"/>
		</xsl:variable>
		<ul>
			<xsl:element name="a">
				<xsl:attribute name="href">./<xsl:value-of select="$categoryID"/>.html</xsl:attribute>
				<xsl:attribute name="target">mainFrame</xsl:attribute>
				<xsl:apply-templates select="Value" /> - <xsl:value-of select="//Category[@id=$categoryID]/Label"/>
			</xsl:element>
		</ul>
	</xsl:template>
</xsl:stylesheet>
